package com.test.controller;


import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.test.comment.UserBean;

import com.test.services.Userservices;

@Controller
@RequestMapping("/user")

public class userController {
	Logger logger = Logger.getLogger(getClass());
	@Autowired
	public Userservices userservices;

	@ResponseBody
	@RequestMapping("/login")
	public ModelAndView login(String usercode, String password, String role,HttpSession session) {
		UserBean userBean = new UserBean();
		userBean.setUsercode(usercode);
		userBean.setPassword(password);
		userBean.setUserType(role);
		logger.debug(usercode);
		logger.debug(password);
		logger.debug(role);
		logger.debug("selectuser start");
		UserBean a = userservices.selectuser(userBean);
		logger.debug("selectuser end");
		if (a != null) {
			session.setAttribute("user", a);
			
			if (role.equals("2")) {
				return new ModelAndView("WEB-INF/jsp/SystemAdmin");
			} else if (role.equals("3")) {
				return new ModelAndView("WEB-INF/jsp/ActiveAdmin");
			} else if (role.equals("1")) {
				return new ModelAndView("WEB-INF/jsp/JudgesScore");
			} else {
				return new ModelAndView("WEB-INF/jsp/vote");
			}
		}else {
			return new ModelAndView("login");
		}

	}
	
}
